#include "Weapon.h"
#include "LevelManager.h"
#include "ResourceDatabase.h"
Weapon::Weapon()
:weaponId(0)
,speed(1)
,cooldown(0)
{
}

void Weapon::update(double delta)
{
    if(cooldown>0)
    {
        cooldown-=delta;
        if(cooldown<0)
            cooldown = 0;
    }
}

void Weapon::shoot(const sf::Vector2f& position,const sf::Vector2i& targetPos)
{
    if(!cooldown)
    {
        cooldown = speed;
        //Create speed vector
        sf::Vector2f speed((float)targetPos.x - position.x,(float)targetPos.y - position.y);
        speed/=sqrt(pow(speed.x,2)+pow(speed.y,2));
        // Should change 1000 to bullet speed
        speed.x=speed.x*1000;
        speed.y=speed.y*1000;
        // Create new bullet
        ProjectilePtr ptr(new Projectile(position,speed,IMG_BULLET));
        // get projectiles vector, add projectile to it
        std::vector<ProjectilePtr> &bullets = LevelManager::get().getCurrentLevel()->getProjectiles();
        bullets.push_back(ptr);
    }
}

void Weapon::setWeapon()
{
    // ToDo: Code to set Weapon
}